# encoding=utf-8

"""ScanCache
    扫描缓存内存类，提供的功能如下:
        1. 缓存文件列表
        2. 比较文件列表, 返回和上一次文件列表不同的列表
"""


class ScanCache:
    def __init__(self, cache_list):
        self.cache_list = cache_list

    def update_file_cache(self, new_cache_list):
        self.cache_list = new_cache_list

    def compare_cache(self, new_cache_list):
        s_o, s_n = set(self.cache_list), set(new_cache_list)

        # old - new != [], 代表目录迁移或者文件丢失
        differ1 = s_o - s_n
        # new - old != [], 代表文件有新增
        differ2 = s_n - s_o

        return list(differ1), list(differ2)


if __name__ == '__main__':
    list1 = [1, 2, 3, 4, 5]
    list2 = [3, 4, 5, 6, 7]

    c = ScanCache(list1)
    d1, d2 = c.compare_cache(list2)
    print(d1, d2)
